package com.example.ui.contact.adapter;

import java.util.ArrayList;
import java.util.List;

import com.example.huashangapp.R;
import com.example.ui.contact.bean.NoticeItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class NoticeAdapter extends BaseAdapter{
	private List<NoticeItem> msgList = new ArrayList<NoticeItem>();// 消息对象数组
	private Context mContext;
	private LinearLayout noticeLayout;
	
	public NoticeAdapter(Context mContext,LinearLayout noticeLayout,List<NoticeItem> msgList ){
		
		this.mContext = mContext;
		this.noticeLayout = noticeLayout;
		this.msgList = msgList;
		
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null; 
		convertView=null;
		if(convertView==null){
			holder = new Holder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.chat_notice_item, null);
			holder.content=(TextView)convertView.findViewById(R.id.chat_notice_item_content);
			holder.time=(TextView)convertView.findViewById(R.id.chat_notice_item_time);
			convertView.setTag(holder);
		}else{
			holder = (Holder)convertView.getTag();
		}
		//		holder.content.setText(listData.get(position).get("content").toString());
		//		holder.time.setText(listData.get(position).get("time").toString());
		String content = msgList.get(position).getContent();
		String time = msgList.get(position).getDateLine();
		holder.content.setText(content);
		holder.time.setText(time);				

		
		return convertView;
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public Object getItem(int position) {
		return position;
	}
	
	@Override
	public int getCount() {
		if(msgList.size()==0){
			noticeLayout.setVisibility(View.VISIBLE);
			return 0;
		}
		noticeLayout.setVisibility(View.GONE);
		return msgList.size();
	}
	
	public void updateMsg(NoticeItem item){
		msgList.add(item);
		notifyDataSetChanged();		
	}
	class Holder {
		TextView content;
		TextView time;
	}
}
